<?php

/**
 * Template class
 * เพื่อตั้งค่าการแสดงผล ในส่วนที่ซ้ำๆของแต่ละหน้าเว็บ
 * @package Theme
 * @subpackage Library
 * @author BeYourCyber
 * @version 1.0 09/01/2011
 */
class Theme_lib {

    /**
     * charset
     * @var string charactor set สำหรับกำหนดที่หน้าเว็บ
     */
    var $charset = 'UTF-8'; // charset หน้าเว็บ
    /**
     * META description
     * @var string meta description
     */
    var $description = ''; // META description
    /**
     * META KEYWORD
     * @var string meta keyword
     */
    var $keywords = ''; // META keywords
    /**
     * META author
     * @var string
     */
    var $author = 'BeYourCyber'; // META author
    /**
     * HTML language
     * @var string show in <html lang="xx">
     * @link http://www.w3schools.com/tags/ref_language_codes.asp
     */
    var $lang = 'th'; // HTML language
    /**
     * Meta generator
     * @var string
     */
    var $generator = 'ChaMongKut CMS - BY MindWebHost.com'; // META generator
    /**
     * META robots
     * @var string META robots (noindex, follow), (index, nofollow), (noindex, nofollow)
     */
    var $robots = 'index, follow'; // META robots (noindex, follow), (index, nofollow), (noindex, nofollow)
    /**
     * title page
     * @var string title
     */
    var $title = ''; // title of web page
    /**
     * array of css file
     * @var array css file
     * @link get_include_css()
     */
    var $filecss = array(); // include all css file
    /**
     * array of js file
     * @var array js file
     * @link get_include_js()
     */
    var $filejs = array(); // include all js file
    /**
     * addition other header
     * @var string code for insert to head
     */
    var $head = ''; // head zone additional code
    /**
     * Additional code jQuery
     * @var string jQuery code
     */
    var $jquery = ''; //add special code to jquery
    /**
     * Additional code CSS
     * @var string css code style
     */
    var $css = ''; // css additional code
    /**
     * Add special parameter body
     * @var string special parameter body <body> >> <body XXXXX>
     */
    var $body = ''; // add special parameter to <body> >> <body XXXXX>
    /**
     * Add special code to footer
     * @var string special code to footer
     */
    var $footer = ''; //add special code to footer page

    /**
     * Current Theme
     * @var string theme name
     */
    var $theme = 'default';

    /**
     * Constructor - Sets Header value
     *
     * The constructor can be passed an array of config values
     */

    function Theme_lib($config = array()) {

        $this->initialize($config);
        log_message('debug', "Theme Class Initialized");
    }

    /**
     * Initialize preferences
     *
     * @access	public
     * @param	array
     * @return	void
     */
    function initialize($config = array()) {
        foreach ($config as $key => $val) {
            if (isset($this->$key)) {
                $method = 'set_' . $key;
                if (method_exists($this, $method)) {
                    $this->$method($val);
                } else {
                    $this->$key = $val;
                }
            }
        }
    }


    function get_theme(){
        return $this->theme;
    }

    function display_css() {
        $tmpcss = '';
        if (isset($this->css{5})) {
            $tmpcss .= '<style type="text/css">';
            $tmpcss .= $this->css;
            $tmpcss .= '</style>';
        }
        return $tmpcss;
    }
    function display_jquery() {
        $tmp = '';
        if (isset($this->jquery{4})) {
            $tmp .= '<script type="text/javascript">
$(document).ready(function() {
';
            $tmp .= $this->jquery;
            $tmp .= '
});
</script>';
        }
        return $tmp;
    }

    function get_meta_description() {
        $tmp = '';
        if (isset($this->description{2})) {
            $tmp .= '<meta name="description" content="' . sprintf('%s', $this->description) . '" />
';
        }
        return $tmp;
    }

    function get_meta_keywords() {
        $tmp = '';
        if (isset($this->keywords{2})) {
            $tmp .= '<meta name="keywords" content="' . sprintf('%s', $this->keywords) . '" />
';
        }
        return $tmp;
    }

    function get_meta_generator() {
        $tmp = '';
        if (isset($this->generator{2})) {
            $tmp .= '<meta name="generator" content="' . sprintf('%s', $this->generator) . '" />
';
        }
        return $tmp;
    }

    function get_meta_robots() {
        $tmp = '';
        if (isset($this->robots{2})) {
            $tmp .= '<meta name="robots" content="' . sprintf('%s', $this->robots) . '" />
';
        }
        return $tmp;
    }

    function get_meta_author() {
        $tmp = '';
        if (isset($this->author{2})) {
            $tmp .= '<meta name="author" content="' . sprintf('%s', $this->author) . '" />
';
        }
        return $tmp;
    }

    function get_title() {
        $tmp = '';
        if (isset($this->title{2})) {
            return $this->title;
        } else {
            return 'Website';
        }
    }

    /**
     * include css เข้าหน้าเว็บ
     * รับ array ชื่อไฟล์ เพื่อนำมารวมกัน และทำงานคู่กับ Files::css()
     * <b>ตัวอย่าง</b>
     * <code>
     * $theme['filecss'] = array('a:c:validationEngine.jquery','a:c:form_signup','a:c:excite-bike:jqui184');
     * </code>
     * @author BeYourCyber
     * @version 1.0
     * @param array ชื่อ ของ css file เช่น 'a:c:fancybox131','a:c:bee' โดย แปลง / ให้เป็น : แทน และไม่ต้องใส่นามสกุล
     * @return string สำหรับนำไป echo ในรูปแบบ <link rel="stylesheet" type="text/css" href="/files/css/%s" />
     * @link Files::css()
     */
    function get_include_css() {
        $tmp = '';
        $CI =& get_instance();
        $css = $CI->theme->config($this->theme.'_config',TRUE);
        $css = $CI->config->config['theme/'.$this->theme.'_config'];
        if (sizeof($css['defaultcss']) > 0) {
            foreach ($css['defaultcss'] as $k => $v) {
                if (isset($x)) {
                    $x .= '--' . $v;
                } else {
                    $x = $v;
                }
            }
        }
        if (sizeof($this->filecss) > 0) {
            foreach ($this->filecss as $k => $v) {
                if (isset($x)) {
                    $x .= '--' . $v;
                } else {
                    $x = $v;
                }
            }
        }
        if(isset($x)){
        $tmp .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />
', site_url('/files/css/'.$x));
            return $tmp;
        }
    }

    /**
     * include javascript เข้าหน้าเว็บ
     * รับ array ชื่อไฟล์ เพื่อนำมารวมกัน และทำงานคู่กับ Files::js()
     * <b>ตัวอย่าง</b>
     * <code>
     * $theme['filejs'] = array('a:j:jquery.validationEngine-th', 'a:j:jquery.validationEngine');

     * </code>
     * @author BeYourCyber
     * @version 1.0
     * @param array ชื่อ ของ js file เช่น 'a:j:jquery.validationEngine-th', 'a:j:jquery.validationEngine' โดย แปลง / ให้เป็น : แทน และไม่ต้องใส่นามสกุล
     * @return string สำหรับนำไป echo ในรูปแบบ <script type="text/javascript" src="./files/js/%s"></script>
     * @link Files::js()
     */
    function get_include_js() {
        $tmp = '';
        $CI =& get_instance();
        $js = $CI->theme->config($this->theme.'_config',TRUE);
        $js = $CI->config->config['theme/'.$this->theme.'_config'];
        if (sizeof($js['defaultjs']) > 0) {
            foreach ($js['defaultjs'] as $k => $v) {
                if (isset($x)) {
                    $x .= '--' . $v;
                } else {
                    $x = $v;
                }
            }
        }
        if (sizeof($this->filejs) > 0) {
            foreach ($this->filejs as $k => $v) {
                if (isset($x)) {
                    $x .= '--' . $v;
                } else {
                    $x = $v;
                }
            }
            
        }
        if(isset($x)){
        $tmp .= sprintf('<script type="text/javascript" src="%s"></script>
', site_url('/files/js/'.$x));
            return $tmp;
        }
    }

    function get_head_addition(){
        $tmp = '';
        if (isset($this->head{2})) {
            return $this->head;
        }
    }
    function get_foot_addition(){
        $tmp = '';
        if (isset($this->footer{2})) {
            return $this->footer;
        }
    }

}

?>
